package com.bomberdroid.model;

/* Imports*/
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;

import com.bomberdroid.R;

public class Map {

	private static final String TAG = Map.class.getSimpleName();

	int mapW;
	int mapH;

	/* images des objets a dessiner sur la map */
	/* passees en attributs de classe pour ne les charger qu'une seule fois */
	private Bitmap background = null;
	private Bitmap blockDes = null;
	private Bitmap blockInd = null;
	private Bitmap[][] player = new Bitmap[10][8];
	private Bitmap playerMort = null;
	private Bitmap[] bonus = new Bitmap[3];
	private Bitmap[] bombe = new Bitmap[12];
	private Bitmap[][] flammes = new Bitmap[7][3];

	public static final int BLOCKSIZE = 48;
	public static final int DECALAGE = 5;

	private int grilleSizeX = 15;
	private int grilleSizeY = 19;
	



	/*
	 * grille representant la map comprenant 19*15 cases, contenant des objets
	 * ou non de type : Bloc-Bombe-Bonus
	 */
	private Objet[][] grille = new Objet[grilleSizeX][grilleSizeY];

	/* Liste des Players, servira a afficher les Players en plus de la map */
	private Player[] listeJ = null;

	/**
	 * Timer qui appele en boucle la methode d'action de chaque Player de la
	 * liste
	 */
	private Timer agir;
	private TimerTask task;

	// private ActionListener tache;

	private int tickCount = 0;

	private int timerRefresh = 15;

	/**
	 * Constructeur par defaut qui initialise une map basique avec 1 utilisateur
	 * 
	 * @param x
	 *            taille x de la fenetre
	 * @param y
	 *            taille y de la fenetre
	 */
	public Map(Resources res) {

		Log.i(TAG, "Constructor (default) " + TAG);

		// resisage
		/**
		 * this.setSize(x, y);
		 */

		// chargement des images
		loadRessources(res);

		// Partie qui alloue la grille d'Objets
		// Parcours la hauteur du tableau
		for (int i = 0; i < 15; i++) {
			// Parcour la ligne correspondant a la hauteur du tableau
			for (int j = 0; j < 19; j++) {
				// si la hauteur est impair, et la largeur aussi
				if (i % 2 != 0 && j % 2 != 0)
					// Alors on place a cet endroit un mur Indestructible
					grille[i][j] = new Indestructible(i, j, grille);
				else
					// Sinon on laisse la case vide en lui allouant null
					grille[i][j] = null;
			}
		}

		/* On ajoute quelques bloc Destructibles */
		this.AjouteDestructible(100);

		/* Creation du tableau de la liste des Players et allocation */
		listeJ = new Player[10];

		listeJ[0] = new Player(0, 0, grille);
		listeJ[1] = new Player(14, 18, grille);
		listeJ[2] = new Player(14, 0, grille);
		listeJ[3] = new Player(0, 18, grille);
		listeJ[4] = new Player(0, 6, grille);
		listeJ[5] = new Player(14, 6, grille);
		listeJ[6] = new Player(7, 0, grille);
		listeJ[7] = new Player(7, 18, grille);
		listeJ[8] = new Player(0, 12, grille);
		listeJ[9] = new Player(14, 12, grille);

		// On implemente l'ActionListener qui fera l'appel de la methode
		// actions() de chaque Player
		/*
		 * tache = new ActionListener() { public void
		 * actionPerformed(ActionEvent evt) { for(Player J : listeJ){
		 * J.actions(); } tickCount++; // Et apres chaque tour de timer on
		 * redessine la map repaint(); } }; agir = new Timer(timerRefresh,
		 * tache); agir.start();
		 */
		
		agir = new Timer();
		agir.schedule(task = new TimerTask() {

			@Override
			public void run() { // TODO Auto-generated method stub
				for (Player J : listeJ) {
					J.actions();
				}
				tickCount++; // Et apres
				// chaque tour de timer on redessine la map
				// Desormais fait dans GamePanel
				// repaint();

			}
		}, 0, timerRefresh);

		Log.i(TAG, "Constructor fin " + TAG);
	}

	/**
	 * Constructeur qui prend la liste des joueurs en parametre
	 * 
	 * @param x
	 *            taille x de la fenetre
	 * @param y
	 *            taille y de la fenetre
	 * @param liste
	 */
	public Map(Player[] liste, Resources res, int width, int height) {
		Log.i(TAG, "Constructor (player) " + TAG);
		/* resisage */
		mapW = width;
		mapH = height;

		/* chargement des ressources */
		loadRessources(res);

		/* Partie qui alloue la grille d'Objets */
		/* Parcour là hauteur du tableau */
		for (int i = 0; i < 15; i++) {
			/* Parcour la ligne correspondant à la hauteur du tableau */
			for (int j = 0; j < 19; j++) {
				/* si la hauteur est impair, et la largeur aussi */
				if (i % 2 != 0 && j % 2 != 0)
					/* Alors on place à cet endroit un mur Indestructible */
					grille[i][j] = new Indestructible(i, j, grille);
				else
					/* Sinon on laisse la case vide en lui allouant null */
					grille[i][j] = null;
			}
		}

		/* On ajoute quelques bloc Destructibles */
		// this.AjouteDestructible(50);

		/* Création du tableau de la liste des joueurs et allocation */
		listeJ = new Player[liste.length];
		for (int i = 0; i < liste.length; i++) {
			listeJ[i] = liste[i];
			Log.i(TAG, "Playerlisting for");
		}
		Log.i(TAG, "agir");
		
		agir = new Timer();
		agir.schedule(new TimerTask() {
			
			@Override
			public void run() { // TODO Auto-generated method stub
				
				for (Player J : listeJ) {
					J.actions();
					
				}
				tickCount++; // Et apres
				// chaque tour de timer on redessine la map

				// repaint();

			}
		}, 0, timerRefresh);

	}

	/**
	 * methode de chargement des ressources, privee car appelee par le
	 * constructeur
	 */
	private void loadRessources(Resources res) {

		this.background = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.map);
		this.blockDes = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.destructible);
		this.blockInd = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.indestructible);

		this.player[0][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_h1);
		this.player[0][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_h2);
		this.player[0][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_b1);
		this.player[0][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_b2);
		this.player[0][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_g1);
		this.player[0][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_g2);
		this.player[0][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_d1);
		this.player[0][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur0_d2);

		this.player[1][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_h1);
		this.player[1][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_h2);
		this.player[1][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_b1);
		this.player[1][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_b2);
		this.player[1][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_g1);
		this.player[1][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_g2);
		this.player[1][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_d1);
		this.player[1][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur1_d2);

		this.player[2][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_h1);
		this.player[2][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_h2);
		this.player[2][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_b1);
		this.player[2][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_b2);
		this.player[2][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_g1);
		this.player[2][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_g2);
		this.player[2][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_d1);
		this.player[2][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur2_d2);

		this.player[3][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_h1);
		this.player[3][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_h2);
		this.player[3][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_b1);
		this.player[3][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_b2);
		this.player[3][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_g1);
		this.player[3][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_g2);
		this.player[3][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_d1);
		this.player[3][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur3_d2);

		this.player[4][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_h1);
		this.player[4][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_h2);
		this.player[4][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_b1);
		this.player[4][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_b2);
		this.player[4][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_g1);
		this.player[4][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_g2);
		this.player[4][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_d1);
		this.player[4][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur4_d2);

		this.player[5][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_h1);
		this.player[5][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_h2);
		this.player[5][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_b1);
		this.player[5][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_b2);
		this.player[5][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_g1);
		this.player[5][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_g2);
		this.player[5][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_d1);
		this.player[5][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur5_d2);

		this.player[6][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_h1);
		this.player[6][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_h2);
		this.player[6][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_b1);
		this.player[6][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_b2);
		this.player[6][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_g1);
		this.player[6][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_g2);
		this.player[6][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_d1);
		this.player[6][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur6_d2);

		this.player[7][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_h1);
		this.player[7][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_h2);
		this.player[7][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_b1);
		this.player[7][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_b2);
		this.player[7][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_g1);
		this.player[7][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_g2);
		this.player[7][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_d1);
		this.player[7][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur7_d2);

		this.player[8][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_h1);
		this.player[8][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_h2);
		this.player[8][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_b1);
		this.player[8][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_b2);
		this.player[8][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_g1);
		this.player[8][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_g2);
		this.player[8][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_d1);
		this.player[8][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur8_d2);

		this.player[9][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_h1);
		this.player[9][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_h2);
		this.player[9][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_b1);
		this.player[9][3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_b2);
		this.player[9][4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_g1);
		this.player[9][5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_g2);
		this.player[9][6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_d1);
		this.player[9][7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur9_d2);

		this.playerMort = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.joueur_mort);
		this.bonus[Bonus.BOMBE] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bonus_bombe);
		this.bonus[Bonus.FLAMME] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bonus_flamme);
		this.bonus[Bonus.ROLLER] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bonus_roller);

		this.bombe[0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe00);
		this.bombe[1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe01);
		this.bombe[2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe02);
		this.bombe[3] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe03);
		this.bombe[4] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe04);
		this.bombe[5] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe05);
		this.bombe[6] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe06);
		this.bombe[7] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe05);
		this.bombe[8] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe04);
		this.bombe[9] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe03);
		this.bombe[10] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe02);
		this.bombe[11] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.bombe01);

		// centre de la flamme
		this.flammes[0][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.centre_0);
		this.flammes[0][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.centre_1);
		this.flammes[0][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.centre_2);
		// flamme horizontale
		this.flammes[1][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_hz_1);
		this.flammes[1][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_hz_2);
		this.flammes[1][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_hz_0);
		// flamme verticale
		this.flammes[2][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_vt_1);
		this.flammes[2][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_vt_0);
		this.flammes[2][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_vt_2);
		// flamme gauche
		this.flammes[3][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_lf_1);
		this.flammes[3][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_lf_0);
		this.flammes[3][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_lf_2);
		// flamme droite
		this.flammes[4][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_rg_1);
		this.flammes[4][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_rg_0);
		this.flammes[4][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_rg_2);
		// flamme haut
		this.flammes[5][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_tp_1);
		this.flammes[5][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_tp_0);
		this.flammes[5][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_tp_2);
		// flamme bas
		this.flammes[6][0] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_bt_1);
		this.flammes[6][1] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_bt_0);
		this.flammes[6][2] = (Bitmap) BitmapFactory.decodeResource(res, R.drawable.flamme_bt_2);

	}

	public Objet[][] getGrille() {
		return grille;
	}

	public Player[] getListeJ() {
		return listeJ;
	}

	public void setGrille(Objet[][] grille) {
		this.grille = grille;
	}

	public void setGrille(int x, int y, Objet o) {
		this.grille[x][y] = o;
	}

	public void setListeJ(Player[] listeJ) {
		this.listeJ = listeJ;
	}

	/**
	 * affecteur de case
	 * 
	 * @param x
	 *            coordonee x de la case a affecter
	 * @param y
	 *            coordonee y de la case a affecter
	 * @param val
	 *            objet a inserer
	 */
	public void setCase(int x, int y, Objet val) {
		this.grille[x][y] = val;
	}

	public Player getPlayer(int i) {
		return listeJ[i];
	}
	
	public int getMapWidth() {
		return grilleSizeY * BLOCKSIZE;
	}

	public int getMapHeight() {
		return grilleSizeX * BLOCKSIZE;
	}

	/**
	 * Methode qui va ajouter a la Map n nombre de blocs Destructibles
	 * aleatoirement Methode provisoire qui disparaitra
	 * 
	 * @param n
	 */
	public void AjouteDestructible(int n) {
		/**
		 * si le nombre de destructible a place est superieur ou egale a 222 on
		 * rempli la map de destructible
		 */

		if (n >= 222) {
			for (int i = 0; i < 15; i++) {
				for (int j = 0; j < 19; j++) {
					if (grille[i][j] == null)
						grille[i][j] = new Destructible(i, j, grille);
				}
			}
		}

		// sinon on les places aleatoirement
		else {
			/*
			 * int aleaX, aleaY; while (n>0) { aleaX = new
			 * Random().nextInt(18)+1; aleaY = new Random().nextInt(14)+1; if
			 * (grille[aleaY][aleaX] == null) { grille[aleaY][aleaX] = new
			 * Destructible(aleaY, aleaX, grille); n--; } }
			 */
			for (int i = 1; i < grille[0].length - 1; i++) {
				grille[2][i] = new Destructible(2, i, grille);
				grille[12][i] = new Destructible(12, i, grille);
			}

			for (int i = 3; i < grille.length - 3; i++) {
				grille[i][2] = new Destructible(i, 2, grille);
				grille[i][16] = new Destructible(i, 16, grille);
			}
		}
	}

	public void onDraw(Canvas canvas) {

		/* affichage du fond de map */
		canvas.drawBitmap(background, 0, 0, null);

		/* boucle forfor qui parcours la grille d'objets */
		for (int i = 0; i < this.grille.length; i++) {
			for (int j = 0; j < this.grille[0].length; j++) {
				/* si l'objet courrant est une instance de Destrcutible */
				if (this.grille[i][j] instanceof Destructible) {
					/* on affiche un bloc desctructible */
					canvas.drawBitmap(blockDes, j * BLOCKSIZE, i * BLOCKSIZE, null);
				}
				/*
				 * pareil, mais avec des else if et des Indestructibles et des
				 * bombes =)
				 */
				else if (this.grille[i][j] instanceof Indestructible) {
					canvas.drawBitmap(blockInd, j * BLOCKSIZE, i * BLOCKSIZE, null);
				} else if (this.grille[i][j] instanceof Bombe) {
					canvas.drawBitmap(bombe[Bombe.getAnim()], j * BLOCKSIZE, i * BLOCKSIZE, null);
				} else if (this.grille[i][j] instanceof Flamme) {
					Flamme tmp = (Flamme) this.grille[i][j];
					canvas.drawBitmap(flammes[tmp.getType()][Flamme.getFlammeAnim()], j * BLOCKSIZE, i * BLOCKSIZE, null);
				} else if (this.grille[i][j] instanceof Bonus) {
					Bonus tmp = (Bonus) this.grille[i][j];
					canvas.drawBitmap(bonus[tmp.getType()], j * BLOCKSIZE, i * BLOCKSIZE, null);
				}
			}
		}

		/* Affichage des Players : boucle for */
		for (int i = 0; i < listeJ.length; i++) {
			if (listeJ[i].isMort()) {
				canvas.drawBitmap(playerMort, listeJ[i].getX(), listeJ[i].getY(), null);
			} else {
				if (tickCount % 10 == 0) {
					int animation = (listeJ[i].getAnim()) / 2;
					int numImage = listeJ[i].getAnim() % 2;
					switch (animation) {
					case Player.HAUT:
						if (listeJ[i].getControl(Player.HAUT) instanceof Date) {
							if (numImage == 0) {
								listeJ[i].setAnim(listeJ[i].getAnim() + 1);
							} else {
								listeJ[i].setAnim(listeJ[i].getAnim() - 1);
							}
							break;
						}
					case Player.BAS:
						if (listeJ[i].getControl(Player.BAS) instanceof Date) {
							if (numImage == 0) {
								listeJ[i].setAnim(listeJ[i].getAnim() + 1);
							} else {
								listeJ[i].setAnim(listeJ[i].getAnim() - 1);
							}
							break;
						}
					case Player.GAUCHE:
						if (listeJ[i].getControl(Player.GAUCHE) instanceof Date) {
							if (numImage == 0) {
								listeJ[i].setAnim(listeJ[i].getAnim() + 1);
							} else {
								listeJ[i].setAnim(listeJ[i].getAnim() - 1);
							}
							break;
						}
					case Player.DROITE:
						if (listeJ[i].getControl(Player.DROITE) instanceof Date) {
							if (numImage == 0) {
								listeJ[i].setAnim(listeJ[i].getAnim() + 1);
							} else {
								listeJ[i].setAnim(listeJ[i].getAnim() - 1);
							}
							break;
						}
					}
				}
				canvas.drawBitmap(player[i][listeJ[i].getAnim()], listeJ[i].getX(), listeJ[i].getY(), null);
			}
		}

	}

	/**
	 * utile ?
	 */
	@Override
	public void finalize() throws Throwable {
		agir.cancel();
	}

}
